FROM ubuntu:18.04

ENV LANGUAGE en
ENV LANG en_US.utf-8

# Install some requirement
RUN sed -i 's|http://archive.ubuntu.com|[trusted=yes] http://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list && \
    sed -i 's|http://security.ubuntu.com|[trusted=yes] http://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list && \
    apt clean -y && \
    apt -y update && \
    apt remove python* -y && \
    apt install python3.8 dosfstools mtools gcc g++ make zlib* libffi-dev curl -y && \
    apt install python3-pip -y && \
    apt install scons -y && \
    ln -s /usr/bin/pip3 /usr/bin/pip

# Install python packages 
# here use pypi.mirrors.zucc.edu.cn , have high speed in HangZhou
# can change to https://pypi.mirrors.tuna.tsinghua.edu.cn/simple
RUN pip install -i https://pypi.mirrors.zucc.edu.cn/simple pip -U && \
    pip config set global.index-url https://pypi.mirrors.zucc.edu.cn/simple && \
    pip install setuptools && \
    pip install kconfiglib && \
    pip install pycryptodome && \
    pip install six --upgrade --ignore-installed six && \
    pip install ecdsa

# Fix Dash
RUN rm -rf /bin/sh && \
    ln -s /bin/bash /bin/sh

#Setup gn
RUN mkdir /tools && \ 
    cd /tools && \
    curl -LO https://repo.huaweicloud.com/harmonyos/compiler/gn/1523/linux/gn.1523.tar && \
    tar xvf /tools/gn.1523.tar && \
    chmod a+x /tools/gn && \
    mv gn/gn /usr/bin/gn

#Setup LLVM
#ADD ./llvm-linux-9.0.0-34042.tar /tools
RUN cd /tools && \
    curl -LO https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-34042/linux/llvm-linux-9.0.0-34042.tar && \
    tar xvf /tools/llvm-linux-9.0.0-34042.tar && \
    rm /tools/llvm-linux-9.0.0-34042.tar && \
    echo "export PATH=/tools/llvm/bin:$PATH" >> /etc/profile 
ENV PATH /tools/llvm/bin:$PATH

#Setup hc-gen
RUN cd /tools && \
    curl -LO https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar && \
    tar xvf /tools/hc-gen-0.65-linux.tar && \
    rm /tools/hc-gen-0.65-linux.tar && \
    echo "export PATH=/tools/hc-gen:$PATH" >> /etc/profile 
ENV PATH /tools/hc-gen:$PATH

#Setup gcc_riscv32
RUN cd /tools && \
    curl -LO https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz && \
    tar xvf /tools/gcc_riscv32-linux-7.3.0.tar.gz && \
    rm /tools/gcc_riscv32-linux-7.3.0.tar.gz && \
    echo "export PATH=/tools/gcc_riscv32/bin:$PATH" >> /etc/profile 
ENV PATH /tools/gcc_riscv32/bin:$PATH

#Setup ninja
RUN cd /tools && \
    curl -LO https://repo.huaweicloud.com/harmonyos/compiler/ninja/1.9.0/linux/ninja.1.9.0.tar && \
    tar xvf /tools/ninja.1.9.0.tar && \
    rm /tools/ninja.1.9.0.tar && \
    echo "export PATH=/tools/ninja:$PATH" >> /etc/profile 
ENV PATH /tools/ninja:$PATH

WORKDIR /home
VOLUME /home